#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
const int N = 5000 + 10;
int n;
pi P[N];
int f[N];
int res = -1;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> P[i].first >> P[i].second;
  sort(P, P + n);
  for (int i = 0; i < n; ++i) {
    f[i] = 1;
    for (int j = 0; j < i; ++j) {
      if (P[j].second < P[i].second) {
        f[i] = max(f[i], f[j] + 1);
      }
    }
    res = max(f[i], res);
  }
  cout << res << endl;
}
